const router = require('express').Router()
const multer = require('multer')
const { signupValidator, getCode, signin } = require('../validator/ValidatorCore')
const UserController = require('../controller/UserController')
const ArticleController = require('../controller/ArticleController')
const LabelController = require('../controller/LabelController')
const CategoryController = require('../controller/CategoryController')
const LabelUserController = require('../controller/LabelUserController')
const upload = multer({dest: 'public/upload'})

router.get('/', (req, res) => {
  res.send('Hello Express')
})

router.post('/signup', signupValidator, UserController.signup)
router.post('/code', getCode, UserController.getCode)
router.post('/signin', signin, UserController.signin)

router.post('/createArticle', ArticleController.createArticle)
router.get('/articleList', ArticleController.articleList)
router.get('/articleDetail/:id', ArticleController.articleDetail)
router.get('/articleSearch', ArticleController.searchArticle)
router.post('/likeArticle', ArticleController.likeArticle)
router.post('/dislikeArticle', ArticleController.disLikeArticle)

/**
 * 标签
 */
router.post('/createLabel', upload.single('file'), LabelController.create)
router.get('/labelList', LabelController.findLabels)
router.put('/updateLabel/:id', LabelController.updateLabel)
router.delete('/removeLabel/:id', LabelController.removeLabel)

/**
 * 分类
 */
router.post('/category', CategoryController.create)
router.get('/category', CategoryController.categoryList)
router.put('/category', CategoryController.categoryEdit)
router.delete('/category/:id', CategoryController.categoryRemove)

/**
 * 关注标签
 */
router.post('/attention', LabelUserController.create)
router.get('/attention', LabelUserController.getLabelUserList)
router.post('/disAttention', LabelUserController.removeLabelUser)

module.exports = router